
__author__="Rafael Santos (@tucif)"
__date__ ="$28/04/2009 01:54:10 PM$"

import os
import urllib
DEFAULT_IMG_PATH = './res/avatar.jpg'
TWIREX_HOME = "http://twirex.com/"

class Grr():
    def __init__(self, id, message, user, date="", time="", tags=['shdhmc','6'], imgUrl=''):
        self.id = id
        self.message = message
        self.user = user
        self.date = date
        self.time = time
        self.tags = tags
        self.image = self.getImage(imgUrl)

    def __unicode__(self):
        return u'%s:  %s'%(self.user,self.message)

    def getImage(self,imgUrl):
        if imgUrl.endswith('/avatar.jpg') or not imgUrl:
            return DEFAULT_IMG_PATH

        imgurl = imgUrl.replace('\\','')
        print imgurl

        imgFileName = imgurl.split("/")[-1]
        path = './res/'+imgFileName
        if os.path.exists(path):
            return path
        try:
            urllib.urlretrieve(imgurl,path)
            return path
        except:
            print "No se pudo cargar imagen"
            return DEFAULT_IMG_PATH


